Skip to content

fix: prevent newlines around quotes in macro invocations - #7157

Open
penguinawesome1 wants to merge 1 commit into
rust-lang:mainfrom
penguinawesome1:macro-string-indent
Open

penguinawesome1 wants to merge 1 commit into
rust-lang:mainfrom
penguinawesome1:macro-string-indent

Conversation

@penguinawesome1

@penguinawesome1 penguinawesome1 commented Oct 4, 2026 •

Copy link
Copy Markdown

Fixes formatting for string literals that contain a newline in macro invocations.

Closes #5029

  • I did not use an LLM to create a change in this PR.
  • I used an LLM to create a change in this PR, and I have explained below how it was used.
    Used to review Rust syntax and for a sanity check (reminded me to use as_str instead of to_string).

@rustbot rustbot added the S-waiting-on-review Status: awaiting review from the assignee but also interested parties. label Oct 4, 2026
Comment thread src/macros.rs
Comment on lines +303 to +315
// Handle special case where there is one argument,
// a string literal containing a newline.
if let [MacroArg::Expr(expr)] = arg_vec.as_slice() {
if let ast::ExprKind::Lit(lit) = expr.kind {
if lit.kind == LitKind::Str && lit.symbol.as_str().contains("\n") {
let rw = format!("{}(\"{}\")", macro_name, lit.symbol);
return match position {
MacroPosition::Item => Ok(format!("{};", rw)),
_ => Ok(rw),
};
}
}
}

@jieyouxu jieyouxu Oct 4, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: this feels very special-cased and somewhat strange to me. I agree the existing formatting doesn't seem great, but I'm not convinced special-casing here makes sense either.

View changes since the review

@ytmimi ytmimi added the A-style-edition-2027 Area: style edition 2027 label Oct 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-style-edition-2027 Area: style edition 2027 S-waiting-on-review Status: awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent formatting between functions and function-like macros

4 participants